package com.lrs.java.j2se_self.lastJava;
import java.util.*;
public class TestCollection {
	public static void main(String[] args){
		List c = new ArrayList();
		//c.add("hello");
		//c.add(new Integer(100));
		c.add(new Name("zhang","lei"));
		c.add(new Name("wu","lin"));
		c.add(new Name("wang","anping"));
		System.out.println(c);
		Collections.sort(c);
		System.out.println(c);
		//c.remove(new Name("zhang","lei"));
		System.out.println(c.size());
		System.out.println(c.contains(new Name("zhang","lei")));
		System.out.println(c);
	}
}
class Name implements Comparable<Name> {
	public String lastName = null;
	public String firstName = null;
	Name (String s1,String s2){
		firstName = s1;
		lastName = s2;
	}

	public boolean equals(Object obj){
		if(obj instanceof Name){
			Name name = (Name)obj;
			return firstName.equals(name.firstName) && lastName.equals(name.lastName);
		}
		return super.equals(obj);
	}
	public int hashCode(){
		return firstName.hashCode();
	}
	public String toString(){
		return firstName + " " + lastName;
	}
	public  int compareTo(Name o){
		//Name  n = (Name)o;
		int lastcmp = lastName.compareTo(o.lastName);
		return lastcmp != 0 ? lastcmp : firstName.compareTo(o.firstName);
	}
	
}